<html>
<head><meta charset="utf-8"><title>File watching and Cargo.toml vs project.json · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html">File watching and Cargo.toml vs project.json</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="229732661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229732661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229732661">(Mar 10 2021 at 20:00)</a>:</h4>
<p>I've noticed that when using Cargo.toml projects, adding new dependencies to crates seems to be picked up immediately, as if the Cargo.toml files are being watched (or if the LSP / extension is seeing the edits and acting accordingly).</p>
<p>It appears that editing the Cargo.toml files causes a reload of the whole workspace.  But I know that project.json files aren't similarly reloaded.   (otoh, the ~600 crates that the <code>rust-analyzer</code> workspace contains doesn't take long to process vs. the ~3000 that I have in my project.json).</p>
<p>Is the Cargo.toml reprocessing done through watching on the filesystem, or via the IDE (and is that what the "client" watcher is, the IDE?)</p>



<a name="229733785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229733785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229733785">(Mar 10 2021 at 20:06)</a>:</h4>
<p>I believe we are effectively using the IDE as a file watcher for Cargo.toml, at least with the default config</p>



<a name="229733878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229733878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229733878">(Mar 10 2021 at 20:07)</a>:</h4>
<p>You can also tell r-a to use a native file watching implementation, but I'm not sure if Cargo.toml works with that setting</p>



<a name="229733903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229733903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229733903">(Mar 10 2021 at 20:07)</a>:</h4>
<p>Is that setup in <code>switch_workspace</code>?</p>



<a name="229734193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229734193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229734193">(Mar 10 2021 at 20:09)</a>:</h4>
<p>I'm torn on whether I want it to watch my <code>project.json</code>, but it would probably be a usability improvement.  (when adding new crates/deps I end up telling r-a to reload the workspace a bunch)</p>



<a name="229738540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229738540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229738540">(Mar 10 2021 at 20:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="301314">woody77</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson/near/229733903">said</a>:</p>
<blockquote>
<p>Is that setup in <code>switch_workspace</code>?</p>
</blockquote>
<p>Yes, looks like it</p>



<a name="229738646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229738646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229738646">(Mar 10 2021 at 20:32)</a>:</h4>
<p>At least it decides whether to use the client's functionality or the builtin watcher</p>



<a name="229746316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229746316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229746316">(Mar 10 2021 at 21:17)</a>:</h4>
<p>I think we currently only listen to <code>didSave</code> for Cargo.toml, which is a <a href="https://github.com/rust-analyzer/rust-analyzer/issues/5333">problem</a></p>



<a name="229746508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229746508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229746508">(Mar 10 2021 at 21:18)</a>:</h4>
<p>hmm, yeah</p>



<a name="229747587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229747587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229747587">(Mar 10 2021 at 21:25)</a>:</h4>
<p>Yeah it's just <code>didSave</code> for the moment: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/16a76aa158d0898d6a46d7bba7310150555a69b9/crates/rust-analyzer/src/main_loop.rs#L123-L131">https://github.com/rust-analyzer/rust-analyzer/blob/16a76aa158d0898d6a46d7bba7310150555a69b9/crates/rust-analyzer/src/main_loop.rs#L123-L131</a></p>



<a name="229754905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229754905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229754905">(Mar 10 2021 at 22:07)</a>:</h4>
<p>Oh, interesting....  And since project.json is (I assume) usually generated, not edited (at least it is for us), then adding "project.json" to that list wouldn't really work (although it would allow for hand-edits...)</p>



<a name="229755110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229755110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229755110">(Mar 10 2021 at 22:08)</a>:</h4>
<p>Although, would VSCode tell the LSP that the file changed because VSCode's own file-watcher detected a change?  or would it need to be open in an editor for that to happen?</p>



<a name="229755680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229755680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229755680">(Mar 10 2021 at 22:10)</a>:</h4>
<p><code>didSave</code> only happens if you actually edit it in the editor. that's the problem. There is a separate mechanism with which we can register file watchers, but we don't use it for Cargo.toml yet (I think because it's not completely trivial because we'd have to add it to the VFS)</p>



<a name="229755705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229755705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229755705">(Mar 10 2021 at 22:10)</a>:</h4>
<p>For <code>didSave</code>, you have to save the file with the editor, not outside</p>



<a name="229756223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229756223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229756223">(Mar 10 2021 at 22:12)</a>:</h4>
<p>Ok, that makes sense.  And the VFS isn't used to watch files if VSCode is the watcher, correct?</p>



<a name="229764180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229764180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229764180">(Mar 10 2021 at 23:10)</a>:</h4>
<p>Right. I think there's a setting for it... or there was a long time ago...</p>



<a name="229942720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229942720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229942720">(Mar 11 2021 at 22:52)</a>:</h4>
<p>There are still settings around that, yes.</p>



<a name="229946520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/File%20watching%20and%20Cargo.toml%20vs%20project.json/near/229946520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/File.20watching.20and.20Cargo.2Etoml.20vs.20project.2Ejson.html#229946520">(Mar 11 2021 at 23:24)</a>:</h4>
<p>So in general, it sounds like for <code>project.json</code>, we don't have any short paths to more automatic support than to reload the extension...  And from looking at things, by the time we're setting up file watching, we've elided the source of the workspace(s) / a crate graph, divorced from the Cargo.toml or project.json that created it.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>